package com.gree.scmservice.controller;


import com.gree.common.annotation.Log;
import com.gree.common.entity.ReturnVo;
import com.gree.common.enums.BusinessType;
import com.gree.common.utils.ReturnCode;
import com.gree.common.utils.StringUtils;
import com.gree.framework.entity.SysUser;
import com.gree.framework.service.GscmUserService;
import com.gree.framework.utils.SecurityUtils;
import net.coobird.thumbnailator.Thumbnails;
import org.nutz.dao.entity.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;

/**
 * 用户信息
 *
 * @author shqiwei
 */


@RestController
@RequestMapping("/user/profile")
public class SysProfileController {

    @Autowired
    private GscmUserService gscmUserService;

    /**
     * 获取当前登录用户信息
     */
    @GetMapping
    public ReturnVo getProfile() {
        SysUser user = SecurityUtils.getUser().getUser();
        SysUser profileUser = gscmUserService.finduserWithClient(user.getUsid(), user.getComp(),"greescmdb2");
        return new ReturnVo<>(ReturnCode.SUCCESS, "success", profileUser);
    }

    /**
     * 更新当前登录用户信息
     */
    @Log(title = "个人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public ReturnVo updateUserProfile(@RequestBody SysUser user) {

        int result = gscmUserService.updateUserProfile(user);
        if (result > 0) {
            return new ReturnVo<>(ReturnCode.SUCCESS, "更新成功");
        } else {
            return new ReturnVo<>(ReturnCode.FAIL, "更新失败,请联系管理员");
        }
    }


}
